package freespiritsocial.io.user.ui.adapter

import android.text.Html
import androidx.core.view.isVisible
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import freespiritsocial.io.user.R
import freespiritsocial.io.user.data.model.bean.CommentPojo
import freespiritsocial.io.user.databinding.ItemPostSubCommentsBinding
import freespiritsocial.io.user.util.CacheUtil
import freespiritsocial.io.user.viewmodel.PostDetailViewModel
import java.util.*

/**
 * 帖子子评论
 */
class PostSubCommentsAdapter(
    data: ArrayList<CommentPojo>? = arrayListOf(),
    layoutResIdRes: Int = R.layout.item_post_sub_comments
):
    BaseQuickAdapter<CommentPojo,BaseDataBindingHolder<ItemPostSubCommentsBinding>>(layoutResIdRes,data) {
    val userId by lazy(LazyThreadSafetyMode.NONE) {
        CacheUtil.getUser()?.userId ?: ""
    }

    override fun convert(holder: BaseDataBindingHolder<ItemPostSubCommentsBinding>,item: CommentPojo) = with(holder.dataBinding) {
        this?.data = item
        holder.dataBinding?.tvComment?.text = Html.fromHtml(item.subComment)
        this?.tvReply?.isVisible = item.commentUserId != userId
    }
}